<template>
  <div class="errlog">
    <div class="container-fluid">
      <div class="row">
        <div class="col-sm-3 col-md-2">
          <Nav class="hidden-xs-only"></Nav>
        </div>
        <div class="col-sm-9 col-md-10">
          <h3>报错日志</h3>
          <el-table
              :data="errAll"
              style="width: 100%">
            <el-table-column
                prop="time"
                label="时间"
                width="100">
            </el-table-column>
            <el-table-column
                prop="uid"
                label="用户"
                width="50">
            </el-table-column>
            <el-table-column
                prop="err_main"
                label="信息">
            </el-table-column>
          </el-table>

          <el-pagination
              class="hidden-sm-and-up"
              style="margin: 12px 0px;float: right"
              background
              @current-change="handleCurrentChange"
              :current-page="currentPage"
              :page-size="pagesize"
              layout="prev, pager, next, jumper"
              :total="errAllCount"
          >
          </el-pagination>
          <el-pagination
              class="hidden-xs-only"
              style="margin: 12px 0px;float: right"
              background
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage"
              :page-sizes="[5, 10, 20, 40 ,100]"
              :page-size="pagesize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="errAllCount"
          >
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Nav from "@/components/Nav";
import {getErrorLog} from "../utils/api";
import utils from "@/utils/time"
export default {
  name: "errLog",
  components: {
    Nav
  },
  data(){
    return {
      errAll:[],
      pagesize:10, //每页显示条目个数
      currentPage:1, //当前页数
      errAllCount:30, //总数量
    }
  },
  methods:{
    handleCurrentChange(v){
      this.currentPage = v
      this.getErrAll((v-1)*this.pagesize,this.pagesize)
    },
    handleSizeChange(v){
      this.pagesize = v
      this.getErrAll((this.currentPage-1)*v,v)
    },
    getErrAll(start,step){
      getErrorLog({start,step}).then(res=>{
        this.errAllCount = res?.body?.count || 0
        this.errAll = res?.body?.main
        this.errAll.forEach(v=>{
          v.time = utils.timestampToTime(v.time,5)
        })
      }).catch(err=>{
        console.log(err)
      })
    }
  },
  created() {
    this.getErrAll((this.currentPage-1)*this.pagesize,this.pagesize)
  }
}
</script>

<style scoped>
.errlog{

}
.errlog h3{
  margin-left: 20px;
}
</style>
